/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.dhecp.project.system.service.impl;

import java.util.List;
import java.util.Map;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.utils.StringUtils;
import com.dhecp.project.system.domain.SysRuleSet;
import com.dhecp.project.system.mapper.SysRuleSetMapper;
import com.dhecp.project.system.service.SysRuleSetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;

/**
 * 
 * @author DH-Xxj
 * @version 2019年8月27日
 */

@Service
public class SysRuleSetServiceImpl implements SysRuleSetService {

	@Autowired
	private SysRuleSetMapper rulesetMapper;
	
	/**通过guid查询规则设置
	 * @return SysRuleSet
	 */
	@Override
	public SysRuleSet querySysRuleSetByGuid(String guid) {
		return rulesetMapper.findSysRuleSetByGuid(guid);
	}

	/**
	 * 通过传入的条件查询规则设置列表
	 * @param 若存在键"nowherestr"（任意值），表示不进行条件过滤
	 * @return List-SysRuleSet
	 * @throws Exception
	 * @author DH-Xxj
	 */
	@Override
	public List<SysRuleSet> querySysRuleSetList(Map<String, Object> params) throws Exception {
		return rulesetMapper.findSysRuleSetList(params);
	}
	
	/**
	 * 通过传入的条件查询规则设置列表
	 * @param 若存在键"nowherestr"（任意值），表示不进行条件过滤
	 * @return List-SysRuleSet
	 * @author DH-Xxj
	 */
	@Override
	public List<SysRuleSet> querySysRuleSetForPage(String moduleTable){
		return rulesetMapper.findSysRuleSetForPage(moduleTable);
	}

	/**修改规则设置
	 * @return MessageModel
	 */
	@Override
	public AjaxResult updateSysRuleSet(String SysRuleSetItems) {
		if (StringUtils.isEmpty(SysRuleSetItems)) {
			return AjaxResult.error("数据提交失败，必填参数有误！");
		}
		List<SysRuleSet> SysRuleSetList = JSON.parseArray(SysRuleSetItems, SysRuleSet.class);
		if (SysRuleSetList == null || SysRuleSetList.size() == 0) {
			return AjaxResult.error("数据包格式有误，请检查！");
		}
		for (SysRuleSet SysRuleSet : SysRuleSetList) {
			rulesetMapper.update(SysRuleSet);
		}
		return AjaxResult.success("操作成功！");
	}

	/**修改规则设置禁用标志
	 * @return MessageModel
	 */
	@Override
	public AjaxResult updateSysRuleSetBdeleted(String SysRuleSetItems) {
		if (StringUtils.isEmpty(SysRuleSetItems)) {
			return AjaxResult.error("数据提交失败，必填参数有误！");
		}
		List<SysRuleSet> SysRuleSetList = JSON.parseArray(SysRuleSetItems, SysRuleSet.class);
		if (SysRuleSetList == null || SysRuleSetList.size() == 0) {
			return AjaxResult.error("数据包格式有误，请检查！");
		}
		for (SysRuleSet SysRuleSet : SysRuleSetList) {
			rulesetMapper.updateSysRuleSetBdeleted(SysRuleSet);
		}
		return AjaxResult.success("操作成功！");
	}

}
